package com.atguigu.tingshu.dispatch.config;

import com.atguigu.tingshu.dispatch.properties.XXLJobProperties;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class XXLJobConfiguration {

    @Autowired
    private XXLJobProperties xxlJobProperties ;

    @Bean
    public XxlJobSpringExecutor xxlJobSpringExecutor() {        // 配置一个xxl job所对应的spring的执行器

        // 常见XxlJobSpringExecutor对象
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor() ;
        // 指定调度中心的访问地址
        xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
        // 指定调度中心的访问token，需要和调度中心的配置一致
        xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
        // 配置执行器所在服务器的ip地址
        xxlJobSpringExecutor.setIp(xxlJobProperties.getIp());
        // 配置执行器端口号,默认值为9999
        xxlJobSpringExecutor.setPort(xxlJobProperties.getPort());
        // 配置执行器名称
        xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppName());

        // 返回
        return xxlJobSpringExecutor ;

    }

}